//package gupao.concurrency.kms;
//
//import gupao.concurrency.utils.RSAUtil;
//import lombok.extern.slf4j.Slf4j;
//
//import java.io.File;
//import java.io.FileWriter;
//import java.io.IOException;
//import java.security.PrivateKey;
//import java.security.PublicKey;
//import java.util.ArrayList;
//import java.util.LinkedHashMap;
//import java.util.List;
//import java.util.UUID;
//
//@Slf4j
//public class MockRequestFileGenerator {
//    public static void main(String[] args) throws Exception {
//        generateMockFile();
//    }
//
//    private static void generateMockFile() throws Exception {
//        SimpleRequestValidator rv = new SimpleRequestValidator();
//        long time = System.currentTimeMillis();
//        List<String> idSignList = new ArrayList<>();
//        for(int i = 0; i < 1000; i++){
//            idSignList.add(test(rv, i+1));
//        }
//        log.info("{}ms", (System.currentTimeMillis()-time));
//        writeMockFile(idSignList);
//    }
//
//    private static String test(SimpleRequestValidator rv, int idx) throws Exception {
//        String id = UUID.randomUUID().toString();
//        LinkedHashMap<String, String> map = new LinkedHashMap<>();
//        RequestModel rm = new RequestModel(map, null);
//
//
//        PublicKey myPublicKey = RSAUtil.getPublicKey(KeyHolderMock.MY_PUBLIC_KEY);
//        PrivateKey myPrivateKey = KeyHolderMock.getPrivateKey();
//        String encryptId = RSAUtil.encrypt(id, myPublicKey);  // self key
//        String decryptId = RSAUtil.decrypt(encryptId, myPrivateKey); // self key
//
//        log.info("{}#id: {}",idx,id);
//        log.info("{}#encryptId: {}",idx, encryptId);
//        log.info("{}#decryptId: {}", idx, decryptId);
//        map.put("id", encryptId);
//        PrivateKey rfPrivateKey = RSAUtil.getPrivateKey(KeyHolderMock.RF_PRIVATE_KEY);
//        PublicKey rfPublicKey = KeyHolderMock.getPublicKey("rf");
//        String sign = RSAUtil.sign(rm.getJoinedReqParamStr(), rfPrivateKey);
//
//        boolean result = RSAUtil.verify(rm.getJoinedReqParamStr(), rfPublicKey, sign);
//        log.info("{}#Sign: {}, validate: {}", idx, sign, result);
//
//        //id, sign
//        return encryptId +","+sign + "\n";
//    }
//
//    static void writeMockFile(List<String> idSignList) throws IOException {
//        File mockFile = new File("mock_file.txt");
//        FileWriter fw = new FileWriter(mockFile.getName(), true);
//        try{
//            for(String idSign : idSignList){
//                fw.write(idSign);
//            }
//        }finally {
//            fw.close();
//        }
//    }
//}
